package com.ruoyi.system.service.impl;

import java.util.Calendar;
import java.util.List;

import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.utils.code.QRcodeImageUtil;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TmcVisitorManageMapper;
import com.ruoyi.system.domain.TmcVisitorManage;
import com.ruoyi.system.service.ITmcVisitorManageService;

/**
 * 访客记录Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-03-31
 */
@Service
public class TmcVisitorManageServiceImpl implements ITmcVisitorManageService 
{
    @Autowired
    private TmcVisitorManageMapper tmcVisitorManageMapper;

    /**
     * 查询访客记录
     * 
     * @param id 访客记录ID
     * @return 访客记录
     */
    @Override
    public TmcVisitorManage selectTmcVisitorManageById(Long id)
    {
        return tmcVisitorManageMapper.selectTmcVisitorManageById(id);
    }

    /**
     * 查询访客记录列表
     * 
     * @param tmcVisitorManage 访客记录
     * @return 访客记录
     */
    @Override
    public List<TmcVisitorManage> selectTmcVisitorManageList(TmcVisitorManage tmcVisitorManage)
    {
        return tmcVisitorManageMapper.selectTmcVisitorManageList(tmcVisitorManage);
    }

    /**
     * 新增访客记录
     * 
     * @param tmcVisitorManage 访客记录
     * @return 结果
     */
    @Override
    public Long insertTmcVisitorManage(TmcVisitorManage tmcVisitorManage) throws Exception {
        //生成一组随机的串
        String code = RandomStringUtils.randomAlphanumeric(8)+"-"+RandomStringUtils.randomAlphanumeric(4)+"-"+RandomStringUtils.randomAlphanumeric(4)+"-"+RandomStringUtils.randomAlphanumeric(4)+"-"+RandomStringUtils.randomAlphanumeric(12);
        //根据房屋获取小区ID
        Long comId=tmcVisitorManageMapper.seleCtcompanyId(tmcVisitorManage.getHouseinfoId());
        //获取当前时间
        Calendar calendar = Calendar.getInstance();
        tmcVisitorManage.setCompanyId(comId);
        tmcVisitorManage.setCreatetime(calendar.getTime());
        tmcVisitorManage.setVisitqrcode(code);
        tmcVisitorManageMapper.insertTmcVisitorManage(tmcVisitorManage);
        return tmcVisitorManage.getId();
    }

    /**
     * 修改访客记录
     * 
     * @param tmcVisitorManage 访客记录
     * @return 结果
     */
    @Override
    public int updateTmcVisitorManage(TmcVisitorManage tmcVisitorManage)
    {
        return tmcVisitorManageMapper.updateTmcVisitorManage(tmcVisitorManage);
    }

    /**4450
     * 批量删除访客记录
     * 
     * @param ids 需要删除的访客记录ID
     * @return 结果
     */
    @Override
    public int deleteTmcVisitorManageByIds(Long[] ids)
    {
        return tmcVisitorManageMapper.deleteTmcVisitorManageByIds(ids);
    }

    /**
     * 删除访客记录信息
     * 
     * @param id 访客记录ID
     * @return 结果
     */
    @Override
    public int deleteTmcVisitorManageById(Long id)
    {
        return tmcVisitorManageMapper.deleteTmcVisitorManageById(id);
    }

    @Override
    public TmcVisitorManage selectvisitqrcodeById(String visitqrcode) {

        return tmcVisitorManageMapper.selectvisitqrcodeById(visitqrcode);
    }

    @Override
    public List<TmcVisitorManage> queryVisitorManagelist(Long publicuserId) {
        return tmcVisitorManageMapper.queryVisitorManagelist(publicuserId);
    }
}
